home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / stdio / bug5.c < prev    next >
C/C++ Source or Header  |  1992-04-09  |  1KB  |  61 lines

  1. /* If stdio is working correctly, after this is run infile and outfile
  2.    will have the same contents.  If the bug (found in GNU C library 0.3)
  3.    exhibits itself, outfile will be missing the 2nd through 1023rd
  4.    characters.  */
  5.  
  6. #include <ansidecl.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10.  
  11. static char buf[8192];
  12.  
  13. int
  14. DEFUN_VOID(main)
  15. {
  16.   FILE *in;
  17.   FILE *out;
  18.   static char inname[] = "infile";
  19.   static char outname[] = "outfile";
  20.   int i;
  21.  
  22.   /* Create a test file.  */
  23.   in = fopen (inname, "w+");
  24.   if (in == NULL)
  25.     {
  26.       perror (inname);
  27.       return 1;
  28.     }
  29.   for (i = 0; i < 1000; ++i)
  30.     fprintf (in, "%d\n", i);
  31.  
  32.   out = fopen (outname, "w");
  33.   if (out == NULL)
  34.     {
  35.       perror (outname);
  36.       return 1;
  37.     }
  38.   if (fseek (in, 0L, SEEK_SET) != 0)
  39.     abort ();
  40.   putc (getc (in), out);
  41.   i = fread (buf, 1, sizeof (buf), in);
  42.   if (i == 0)
  43.     {
  44.       perror ("fread");
  45.       return 1;
  46.     }
  47.   if (fwrite (buf, 1, i, out) != i)
  48.     {
  49.       perror ("fwrite");
  50.       return 1;
  51.     }
  52.   fclose (in);
  53.   fclose (out);
  54.  
  55.   puts ("There should be no further output from this test.");
  56.   fflush (stdout);
  57.   execlp ("cmp", "cmp", inname, outname, (char *) NULL);
  58.   perror ("execlp: cmp");
  59.   exit (1);
  60. }
  61.